// ConvertToNMEA.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "ConvertToNMEA.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CConvertToNMEA dialog


CConvertToNMEA::CConvertToNMEA(CWnd* pParent /*=NULL*/)
	: CDialog(CConvertToNMEA::IDD, pParent)
{
	//{{AFX_DATA_INIT(CConvertToNMEA)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CConvertToNMEA::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConvertToNMEA)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConvertToNMEA, CDialog)
	//{{AFX_MSG_MAP(CConvertToNMEA)
	ON_BN_CLICKED(IDC_SaveFile, OnSaveFile)
	ON_BN_CLICKED(IDC_StartConvert, OnStartConvert)
	ON_BN_CLICKED(IDC_StopConvert, OnStopConvert)
	ON_WM_CLOSE()
	ON_MESSAGE (WM_CONVERT_COMPLETE, OnConvertExit)
	ON_MESSAGE (WM_CONVERT_PROGRESS, OnConvertProgress)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConvertToNMEA message handlers

BOOL CConvertToNMEA::OnInitDialog() 
{
	CDialog::OnInitDialog();

	if (!m_ConvertToNMEA.Create(this))
		g_GlobalObj.UIWriteLog("m_ConvertToNMEA.Create Error");
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CConvertToNMEA::OnSaveFile() 
{
	if (!m_ConvertToNMEA.ChooseFileName())
		g_GlobalObj.UIWriteLog("m_ConvertToNMEA.ChooseFileName Error");
}

void CConvertToNMEA::OnStartConvert() 
{
	if(!m_ConvertToNMEA.StartConvert())
		g_GlobalObj.UIWriteLog("m_ConvertToNMEA.StartConvert Error");
	
}

void CConvertToNMEA::OnStopConvert() 
{
	if(!m_ConvertToNMEA.StopConvert())
		g_GlobalObj.UIWriteLog("m_ConvertToNMEA.StopConvert Error");
	
}

void CConvertToNMEA::OnClose() 
{
		OnOK();
//	if(!m_ConvertToNMEA.CloseWindow())
//		g_GlobalObj.UIWriteLog("m_ConnectToMap.CloseWindow Error");
//	CDialog::OnClose();	
}

LONG CConvertToNMEA :: OnConvertExit(UINT wParam, LONG lParam)
{
	if(!m_ConvertToNMEA.ConvertThreadExit())
		g_GlobalObj.UIWriteLog("m_ConnectToMap.ConvertThreadExit Error");
	
	return true;
}

LONG CConvertToNMEA::OnConvertProgress (UINT wParam, LONG lParam)
{
	if (!m_ConvertToNMEA.ConvertProgress((int) lParam))
		g_GlobalObj.UIWriteLog("m_ConvertToNMEA.ConvertProgress Error");

	return true;
}

void CConvertToNMEA::OnOK() 
{
	if(!m_ConvertToNMEA.ShutDown())
		g_GlobalObj.UIWriteLog("m_ConvertToNMEA.ShutDown Error");

	CDialog::OnOK();	
}
